package com.site.wisdom_construction.controller.personnelModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.personnelModule.SafetyTrainingWorkersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/1/6
 * @Description
 */
@Api(tags = "安全教育培训对应人员接口")
@RestController
@RequestMapping("SafetyTrainingWorkers")
@CrossOrigin
public class SafetyTrainingWorkersController {
    @Autowired
    private SafetyTrainingWorkersService safetyTrainingWorkersService;

    @ApiOperation(value = "根据培训id分页查询对应信息", notes = "测试数据:")
    @PostMapping("/findSafetyTrainingWorkersByPage")
    public Page findSafetyTrainingWorkersByPage(@RequestBody Map map) {
        List<Integer> list = (List<Integer>) map.get("list");
        if (list.size()==0){
            list.add(0);
            map.put("list",list);
        }
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(safetyTrainingWorkersService.Total(map));
        page.setItems(safetyTrainingWorkersService.findSafetyTrainingWorkersByPage(map));
        return page;
    }

    @ApiOperation(value = "增加人员培训对应信息", notes = "测试数据:")
    @PostMapping("/insertSafetyTrainingWorkers")
    public JsonResult insertSafetyTrainingWorkers(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        map.put("safetyTrainingId",map.get("id"));
        int i = safetyTrainingWorkersService.insertSafetyTrainingWorkers(map);
        if (i == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("成功");
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除人员培训对应信息", notes = "测试数据:")
    @PostMapping("/deleteSafetyTrainingWorkers")
    public JsonResult deleteSafetyTrainingWorkers(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();
        int i = safetyTrainingWorkersService.deleteSafetyTrainingWorkers(map);
        if (i == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("成功");
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("失败!");
        }
        return jsonResult;
    }
}
